<?php
ob_start(); // 开启输出缓冲
// 先输出 HTML 或其他内容
?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
		    function popDiv(){
		        // 获取div元素
		        var popDiv = document.getElementById("popDiv");
		        // 控制div的显示与隐藏
		        popDiv.style.display = "block";
		    }
		    function closePop(){
		        // 获取弹出窗口元素
		        let popDiv = document.getElementById("popDiv");
		        popDiv.style.display = "none";
		    }
		</script>
		<style>
				#input2{
					width: 25.5px;
					height: 25.5px;
					background-color:#00214f;
					padding: 10px;
					border-radius:5px;
				}
		</style>
	</head>
	<body>
	
	<center>
		<?php
				error_reporting(0);//关闭提示
				$s = $_GET['s'];//防止刷新
				
				require_once('./config.php');
				$con=login();
				
				//操作判断
				$jduser = $_COOKIE["jduser"];//获取cookie用户名
				$jdpassword = $_COOKIE["jdpassword"];//获取cookie用户名
				if (!$con)
				{
					die('MYSQL链接失败: ' . mysqli_error());
				}
				else
				{
						$sql="select tequan FROM user WHERE tequan='admin' and 用户名='$jduser' and 密码='$jdpassword'";
						$panduan=mysqli_query($con,$sql);
						$row = mysqli_fetch_array($panduan);
						if (mysqli_num_rows($panduan) == NULL)
						{
							header("Location:feifalaiyuan.html");
						}

				}		
				
				//删除记录
				$DL = $_POST["neirong"];
				if (!$con)
				{
					die('MYSQL链接失败: ' . mysqli_error());
				}
				else
				{
					if ($DL != NULL)
					{
						$shanchujilu="DELETE FROM user WHERE 用户名='$DL'";
						mysqli_query($con,$shanchujilu);
						echo '<script> alert("已删除"); </script>';
					}
					elseif($s!=NULL and $DL==NULL)
					{echo '<script> alert("失败"); </script>';}
				}		
				
				
				//修改记录
				$yonghuming=$_POST['yonghuming'];
				$mima=$_POST['mima'];
				$QQ=$_POST['QQ'];
				$yonghuminga=$_POST['yonghuminga'];
				if (!$con)
				{
					die('MYSQL链接失败: ' . mysqli_error());
				}
				else
				{
					if ($yonghuming!=NULL and $mima!=NULL and $QQ!=NULL)
					{	
						$shanchujilu="UPDATE user SET 用户名='$yonghuming',密码='$mima',QQ='$QQ' WHERE 用户名='$yonghuminga'";
						mysqli_query($con,$shanchujilu);
						echo '<script> alert("已更新"); </script>';
					}
					elseif($s!=NULL and $yonghuming==NULL and $mima==NULL and $QQ==NULL)
					{echo '<script> alert("失败"); </script>';}
				}
					
				
				//输出有内容	
				 if (!$con)
				 {
					die('MYSQL链接失败: ' . mysqli_error());
				 }
				 else
				 {
					 //输出所有结果
					 $sql = "SELECT * FROM user  order by 用户名 desc";
					 $result = mysqli_query($con,$sql);
					 while($row = mysqli_fetch_array($result))
					   {
						  echo 
						   "<div style='height: auto;width: 800px;margin:0px 0px 15px 5px;background-color: #ffffff;padding: 5px 0px 15px 0px;text-align: left;box-shadow: 0px 0px 3px #888888;border-radius: 10px;'>".
								"<div style='text-align: left;display: flex;padding: 0px 15px 0px 15px;margin:15px 0px 0px 0px;height: 50px;'>".
									"<p style='height: 20px;margin: 0px 0px 0px 10px;padding: 6px 0px 0px 0px;color: #000000;font-size:20px;font-weight:bold;font-family: 微软雅黑;'>".$row['用户名']."</p>".	
								"</div>".
								"<hr style='border: 1px solid #000;padding: 0px;margin: 0px 15px 5px 15px;'>".
								"<div style='text-align: left;padding:0px 15px 0px 15px;margin:0px;'>".
									"<p style='margin: 15px 0px 0px 0px;padding: 0px;text-align: left;color: #000000;font-size:15px;font-family: 微软雅黑;font-weight:bold;'>"."密码:".$row['密码']."<br>QQ:".$row['QQ']."</p>".
								"</div>".
								"<div style='text-align: left;display: flex;padding:0px;margin:10px 0px 10px 15px;'>".
									"<form action='useryemian.php' method='post' style='width: 40px;display: flex;'>".
										"<input type='hidden' name='neirong' value='".$row['用户名']."'>".
										"<input id='input2' type='image'  src='img/delete-forever-outline.png'>".
									"</form>".
								"</div>".
								"<form action='useryemian.php' method='post' style='margin:10px 0px 10px 15px;'>".
									"<input style='width: 190px;height: 35px;border:0px;border-radius:5px;margin-bottom: 5px;padding-left: 15px;background-color: #F5F5F5;' placeholder='用户名修改为' name='yonghuming' type='text'><br>".
									"<input style='width: 190px;height: 35px;border:0px;border-radius:5px;margin-bottom: 5px;padding-left: 15px;background-color: #F5F5F5;' placeholder='密码修改为' name='mima' type='password'><br>".
									"<input style='width: 190px;height: 35px;border:0px;border-radius:5px;margin-bottom: 5px;padding-left: 15px;background-color: #F5F5F5;' placeholder='QQ修改为' name='QQ' type='text'><br>".
									"<input style='width: 207px;height: 40px;border:0px;margin-top: 1px;background-color: #00214f;color:#ffffff;font-weight:bold;border-radius:5px;' type='submit' value='修改'>".
									"<input  name='yonghuminga' type='hidden' value='".$row['用户名']."'><br>".
								"</form>".
						   "</div>";
						}
				 }
		?>
		</center>
	</body>
</html>
